package org.example.springboot_demo1.controllerRequest.json;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.example.springboot_demo1.controllerRequest.person.Person;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:38917
 * Date:2025/4/8
 * Time:17:18
 */
public class Test_Json {
    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        String json = "{\"id\":12,\"name\":\"张三\",\"age\":18}";
        //json字符串转换为对象
        Person person = mapper.readValue(json, Person.class);
        System.out.println(person);
        //对象转换为json字符串
        String s = mapper.writeValueAsString(person);
        System.out.println(s);
    }
}
